<template>
  <div>
    <city-header></city-header>
    <city-search :cities="cities"></city-search>
    <city-list :hotCities="hotCities" :cities="cities" :letter="letter"></city-list>
    <city-alpha :cities="cities" @change="handleLetterChange"></city-alpha>
  </div>
</template>
<script>
import axios from 'axios'
import cityHeader from './components/cityHeader'
import citySearch from './components/citySearch'
import cityList from './components/cityList'
import cityAlpha from './components/cityAlpha'
export default {
  name: 'City',
  data () {
    return {
      hotCities: [],
      cities: {},
      letter: ''
    }
  },
  methods: {
    getCityInfos () {
      axios('api/city.json').then(this.getCityInfosSucc)
    },
    getCityInfosSucc (res) {
      res = res.data
      if (res.ret && res.data) {
        const data = res.data
        this.hotCities = data.hotCities
        this.cities = data.cities
      }
    },
    handleLetterChange (letter) {
      this.letter = letter
    }

  },
  mounted () {
    this.getCityInfos()
  },
  components: {
    cityHeader,
    citySearch,
    cityList,
    cityAlpha
  }
}
</script>
<style lang="stylus" scoped></style>
